﻿#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.dll"
#r @"..\Microsoft.SharePoint.Client (spo)\Microsoft.SharePoint.Client.Runtime.dll"

#load "Client.fs"

open Client
open Microsoft.SharePoint.Client
open Microsoft.SharePoint.Client.Application
open System.Security;
open System.Net
open System

// =======================================================
// Create same notebook as notebook feature
// =======================================================

let web = Client.Context.Web
let siteAssets = Client.Context.Web.Lists.GetByTitle("Site Assets")
Client.Load web
web.ServerRelativeUrl
Client.Load siteAssets

let notebookFolder = siteAssets.RootFolder.Folders.Add("Test Notebook")
Client.ExecuteQuery()
let notebook = siteAssets.GetItemById(notebookFolder.ListItemAllFields.Id)
Client.Load notebook
notebook.["ContentTypeId"] <- "0x0120003CFA98D6A489E54998EAF4CD2E2703F8"
notebook.["HTML_x0020_File_x0020_Type"] <- "OneNote.Notebook"
notebook.Update()
Client.ExecuteQuery()

Client.Load notebook.Folder.ParentFolder
notebook.Folder.ServerRelativeUrl
let result = notebook.GetWOPIFrameUrl(Utilities.SPWOPIFrameAction.Edit)
Client.ExecuteQuery()
